<template>
	<view class="">
		<demo-child ref="child"></demo-child>
		<button @click="child.addCount()">点击一下</button>
		{{ name }}
	</view>
	<view class="">
		<button @click="onDelete">删除</button>
	</view>
	<view class="">
		<button @click="onMenu">菜单</button>
		<button @click="onHome">首页</button>
		<button @click="onDemo1">go demo1</button>
		<button @click="onPerson">个人中心</button>
		<button @click="clearCache">清理缓存</button>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from "vue";
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	const child = ref(null);
	onMounted(() => {
		console.log(child.value);
	});
	const name = ref("");
	onLoad((e) => {
		console.log(e);
		name.value = e.name;
	});
	onShow(() => {
		console.log("onShow函数");
	});
	// uni.showToast({
	// 	title: "提示",
	// 	icon: "error",
	// 	duration: 3000,
	// });
	// uni.showLoading({
	// 	title: "加载中...",
	// });
	const onDelete = function() {
		uni.showModal({
			title: "提示",
			content: "是否删除",
			showCancel: true,
			cancelText: "No",
			confirmText: "Yes",
			success: (res) => {
				if (res.confirm)
					uni.showToast({
						title: "删除成功",
					});
			},
			fail: () => {},
			complete: () => {},
		});
	};
	const xl = ["高中", "本科", "研究生"];
	const onMenu = () => {
		uni.showActionSheet({
			itemList: xl,
			title: "请选择",
			success(res) {
				console.log(res);
				uni.showToast({
					title: xl[res.tapIndex],
				});
				uni.setNavigationBarTitle({
					title: xl[res.tapIndex],
				});
			},
			fail(res) {
				console.log(res);
			},
		});
	};
	const onHome = () => {
		uni.reLaunch({
			url: "/pages/index/index",
		});
	};
	const onDemo1 = () => {
		uni.navigateTo({
			url: "/pages/demo1/demo1",
		});
	};
	const onPerson = () => {
		uni.switchTab({
			url: "/pages/demo3/demo3",
		});
	};
	const clearCache = () => {
		uni.removeStorageSync("name");
	};
</script>

<style lang="scss" scoped></style>